#include "matitem.h"
#include <QPainter>

MatItem::MatItem(const QRectF &rect, QGraphicsItem *parent)
    : QGraphicsRectItem(rect, parent),
      m_type(kTypeEmpty),
      m_colorMap({{kTypeEmpty, Qt::transparent}, {kTypeFill, Qt::magenta}})
{
}

MatItem::~MatItem()
{
}

void MatItem::paint(QPainter *painter,
                    const QStyleOptionGraphicsItem *option,
                    QWidget *widget)
{
    Q_UNUSED(option)
    Q_UNUSED(widget)
    QRectF r = rect();
    painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    // draw background
    QColor c = color(m_type);
    painter->setPen(c);
    painter->setBrush(c);
    painter->drawRect(r);
    // draw coordinate
    /*
    if (c == Qt::transparent) {
        painter->setPen(Qt::black);
    } else {
        painter->setPen(QColor(255-c.red(), 255-c.green(), 255-c.blue(), c.alpha()));
    }
    QFont font = painter->font();
    font.setPointSize(font.pointSize()/2);
    painter->setFont(font);
    QPoint coord = data(kDataPos).toPoint();
    painter->drawText(r, Qt::AlignCenter, QString("%1,%2").arg(coord.x()).arg(coord.y()));
    */
}
